#define _CRT_SECURE_NO_WARNINGS 1
#include"Date.h"

Date::Date(const int year, const int month, const int day)
{
	_year = year;
	_month = month;
	_day = day;
}

void Date::Print()const
{
	cout << _year << "-";
	cout << _month << "-";
	cout << _day << endl;
}

int Date::GetMonthDay(int year, int month)const
{
	static int days[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	int day = days[month];
	if (_month == 2 && _year % 4 == 0 && _year % 100 != 0 || _year % 400 == 0)
	{
		day += 1;
	}
	return day;
}

Date& Date::operator+=(int day)
{
	if (day >= 0)
		_day += day;
	else
		return *this -= -day;
	while (_day > GetMonthDay(_year, _month))
	{
		_day -= GetMonthDay(_year, _month);
		_month += 1;
		if (_month > 12)
		{
			_month -= 12;
			_year += 1;
		}
	}
	return *this;
}

Date& Date::operator-=(int day)
{
	if (day >= 0)
		_day -= day;
	else
		return *this += -day;
	while (_day < 1)
	{
		_month -= 1;
		if (_month == 0 )
		{
			_month = 12;
			_year -= 1;
		}
		_day += GetMonthDay(_year, _month);
	}
	return *this;
}

Date Date::operator+(int day)const
{
	Date ret(*this);
	ret += day;
	return ret;
}

Date Date::operator-(int day)const
{
	Date ret(*this);
	ret -= day;
	return ret;
}


Date& Date::operator++()
{
	*this += 1;
	return *this;
}

Date Date::operator++(int)
{
	Date ret = *this;
	*this += 1;
	return ret;
}

Date& Date::operator--()
{
	*this -= 1;
	return *this;
}


Date Date::operator--(int)
{
	Date ret = *this;
	*this -= 1;
	return ret;
}

bool Date::operator==(const Date& d)const
{
	if (_year == d._year && _month == d._month && _day == d._day)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool Date::operator>(const Date& d)const
{
	if ((_year > d._year)
		|| (_year == d._year && _month > d._month)
		|| (_year == d._year && _month == d._month && _day > d._day))
		return true;
	else
	{
		return false;
	}
}

bool Date::operator>=(const Date& d)const
{
	if (*this > d || *this == d)
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool Date::operator< (const Date& d) const
{
	return !(*this >= d);
}



int Date::operator-(const Date& d)
{
	Date large = *this;
	Date less = d;
	if (*this < d)
	{
		Date large = d;
		Date less = *this;
	}
	int count = 0;
	while (!(less == large))
	{
		if (less + count == large)
		{
			return count;
		}
		count++;
	}
	return 0;
}

ostream& operator<<(ostream& out, const Date& d)
{
	cout << d._year << "-";
	cout << d._month << "-";
	cout << d._day << endl;
	return out;
}

istream& operator>>(istream& in,Date& d)
{
	cin >> d._year >> d._month >> d._day;
	return in;
}